#include <Python.h>

#include <kuai/misc/typedef.hpp>

#ifndef _KUAI_LIBPY_PYTOOL_HPP_
#define _KUAI_LIBPY_PYTOOL_HPP_


namespace kuai { namespace py {

	class Object 
	{
	public:
		explicit Object(PyObject* obj) 
		{
			inc();
		}

		Object(const Object& v1) {
			obj = v1.obj;
			inc();
		}

		virtual ~Object() {
			dec();
		}

		Object& operator=(const Object& v1) {
			obj = v1.obj;
			inc();
		}

		inline void inc() {
			Py_INCREF(obj);
		}

		inline void dec() {
			Py_DECREF(obj);
		}

		Object operator[](const Char szName[]) {
			PyObject* attr = PyObject_GetAttrString(obj, szName);
			if (attr == NULL) {
			}
			else {
				Object result(attr);
				result.dec();
				return result;
			}
		}

	private:
		PyObject* obj;
	};

} }

#endif
